const add0 = (num) => {
  return num < 10 ? '0' + num : num
}
/**
 * 时间戳转时间格式
 * @param time 时间戳
 * @returns {string}
 */
const getDateYMDHMS = (time) => {
  let date = new Date(time);
  let y = date.getFullYear();
  let m = add0(date.getMonth() + 1); //获取当前月份的日期
  let d = add0(date.getDate());

  let hour = add0(date.getHours())
  let minute = add0(date.getMinutes())
  let second = add0(date.getSeconds())
  return y + "-" + m + "-" + d + " " + hour + ":" + minute + ":" + second;
}


/**
 * 获取昨天、今天、明天
 * @param time 时间戳
 * @returns {string}
 */
const getDateYMD = (time, type) => {
  let date = new Date(time);
  let y = date.getFullYear();
  let m = add0(date.getMonth() + 1); //获取当前月份的日期
  let d = add0(date.getDate());

  let result
  switch (type) {
    case 'dot':
      result = y + "." + m + "." + d
      break;
    default:
      result = y + "-" + m + "-" + d
      break;
  }
  return result;
}




module.exports = {
  getDateYMD,
  getDateYMDHMS,
}